home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #3 / Amiga Plus CD - 2002 - No. 03.iso / AmiSoft / Mus / Play / Mhm_mayhem.lha / mhm-mAYhem_deli / hardAY / hardAY.s < prev    next >
Text File  |  2002-08-15  |  6KB  |  456 lines

  1. ;DEBUG set 1
  2. ;READ_OK set 1
  3.  
  4.     XDEF    _hardAY_On
  5.     XDEF    _hardAY_Off
  6.     XDEF    _hardAY_Shut
  7.     XDEF    _hardAY_WrRegList
  8.     XDEF    _hardAY_RdRegList
  9.     XDEF    _hardAY_SetFreq
  10.  
  11.  
  12.     include    exec/exec_lib.i2
  13.     include    resources/misc.i
  14.     include    resources/misc_lib.i
  15.  
  16.  
  17.  IFD DEBUG
  18.     bsr    hardAY_On
  19.  
  20.     bsr    hardAY_Shut
  21.  
  22.     move.l    #1750000,d0
  23.     bsr    hardAY_SetFreq
  24.  
  25.  
  26.     bsr    hardAY_Off
  27.     rts
  28.  
  29. buffer    dc.w    $0000,$0100,$0200,$0300,$0400,$0500,$0600,$07FF
  30.     dc.w    $0800,$0900,$0A00,$0B00,$0C00,$0D00,$0E00,$0F00
  31.  
  32.  
  33.  ENDC
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. DATA_PORT    equ    $BFE101
  42. DATA_DIR    equ    $BFE301
  43. AUX_PORT    equ    $BFD000
  44. AUX_DIR    equ    $BFD200
  45.  
  46. INPUTS    MACRO
  47.     clr.b    DATA_DIR
  48.     ENDM
  49.  
  50. OUTPUTS    MACRO
  51.     st.b    DATA_DIR
  52.     ENDM
  53.  
  54. WR_REG    MACRO
  55.  
  56.     move.b    \1,DATA_PORT    ;set AY register
  57.     or.b    #$05,AUX_PORT
  58.     and.b    #$FA,AUX_PORT
  59.  
  60.     move.b    \2,DATA_PORT    ;write into AY register
  61.     or.b    #$01,AUX_PORT
  62.     and.b    #$FE,AUX_PORT
  63.  
  64.     ENDM
  65.  
  66.  
  67. RD_REG    MACRO
  68.  
  69.     move.b    \1,DATA_PORT    ;set AY register
  70.     or.b    #$05,AUX_PORT
  71.     and.b    #$FA,AUX_PORT
  72.  
  73.     INPUTS
  74.     or.b    #$04,AUX_PORT
  75.     move.b    DATA_PORT,\2    ;read from AY register
  76.     and.b    #$FB,AUX_PORT
  77.     OUTPUTS
  78.  
  79.     ENDM
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. hardAY_On:
  89. _hardAY_On:
  90.     ;grab parallel port, check AY presence
  91.     ;result in d0.l:  0 - success
  92.     ;                +2 - can't grab all port-related stuff
  93.     ;                +1 - no AY
  94.  
  95.     ;in case of success, hardAY_Off must be called to free all stuff
  96.     ;otherwise, everything opened will be closed back before returning
  97.  
  98.     movem.l    d1-d7/a0-a6,-(sp)
  99.  
  100.     move.w    #2,Success
  101.  
  102.     move.l    4.w,a6
  103.     lea    MiscResName(pc),a1
  104.     jsr    _LVOOpenResource(a6)
  105.     move.l    d0,MiscBase
  106.     beq.s    .nores
  107.  
  108.     move.l    d0,a6
  109.     moveq    #MR_PARALLELPORT,d0
  110.     lea    OwnerString(pc),a1
  111.     jsr    _LVOAllocMiscResource(a6)
  112.     tst.l    d0
  113.     bne.s    .nopport
  114.  
  115.     moveq    #MR_PARALLELBITS,d0
  116.     lea    OwnerString(pc),a1
  117.     jsr    _LVOAllocMiscResource(a6)
  118.     tst.l    d0
  119.     bne.s    .nopbits
  120.  
  121.     subq.w    #1,Success
  122.  
  123.     and.b    #$FA,AUX_PORT    ;init port hardware
  124.     or.b    #$05,AUX_DIR
  125.     OUTPUTS
  126.  
  127.     moveq    #7,d0
  128.     moveq    #$78,d1
  129.     bsr.s    .wrreg
  130.  
  131.     clr.b    d1
  132.     bsr.s    .wrreg
  133.     bsr.s    .wrreg
  134.     bsr.s    .wrreg
  135.  
  136.     moveq    #14,d0
  137.     moveq    #(16+6),d1
  138.     bsr.s    .wrreg
  139.  
  140.  IFD READ_OK
  141.     moveq    #7,d0
  142.     bsr.s    .rdreg
  143.  
  144. ;;;;;;;;;;;    cmp.b    #127,d1
  145. ;;;;;;;;;;;    bne.s    .noAY
  146.     addq.b    #1,d1
  147.     bvc.s    .noAY
  148.  
  149.     clr.b    d2
  150.     bsr.s    .rdreg
  151.     bsr.s    .rdreg
  152.     bsr.s    .rdreg
  153.  
  154. ;;;;;;;;;;;    and.b    #$1F,d2
  155.     lsl.b    #3,d2
  156.     bne.s    .noAY
  157.  
  158.     moveq    #14,d0
  159.     bsr.s    .rdreg
  160.     cmp.b    #(16+6),d1
  161.     bne.s    .noAY
  162.  ENDC
  163.     subq.w    #1,Success
  164.  
  165. .nores
  166. .nopport
  167. .return
  168.     moveq    #0,d0
  169.     move.w    Success(pc),d0
  170.  
  171.     movem.l    (sp)+,d1-d7/a0-a6
  172.     rts
  173. .noAY
  174.     move.l    MiscBase(pc),a6
  175.     moveq    #MR_PARALLELBITS,d0
  176.     jsr    _LVOFreeMiscResource(a6)
  177. .nopbits
  178.     moveq    #MR_PARALLELPORT,d0
  179.     jsr    _LVOFreeMiscResource(a6)
  180.  
  181.     bra.s    .return
  182.  
  183.  
  184. .wrreg
  185.     WR_REG    d0,d1
  186.     addq.b    #1,d0
  187.     rts
  188.  
  189. .rdreg
  190.     RD_REG    d0,d1
  191.     addq.b    #1,d0
  192.     or.b    d1,d2
  193.     rts
  194.  
  195.  
  196.  
  197.  
  198. hardAY_Off:
  199. _hardAY_Off:
  200.     ;release all allocations & shut AY
  201.     ;safe to call even if hardAY_ON failed
  202.  
  203.     tst.w    Success
  204.     bne.s    .return
  205.  
  206.     movem.l    d0-d7/a0-a6,-(sp)
  207.  
  208.     bsr.s    hardAY_Shut
  209.  
  210.     move.l    MiscBase(pc),a6
  211.     moveq    #MR_PARALLELBITS,d0
  212.     jsr    _LVOFreeMiscResource(a6)
  213.  
  214.     moveq    #MR_PARALLELPORT,d0
  215.     jsr    _LVOFreeMiscResource(a6)
  216.  
  217.     movem.l    (sp)+,d0-d7/a0-a6
  218. .return
  219.     rts
  220.  
  221.  
  222.  
  223. hardAY_Shut:
  224. _hardAY_Shut:
  225.     ;clear up all AY regs ($07 will be set to $FF)
  226.  
  227.     movem.l    d0/a0,-(sp)
  228.  
  229.     lea    ClearSeq(pc),a0
  230.     moveq    #16,d0
  231.     bsr.s    hardAY_WrRegList
  232.  
  233.     movem.l    (sp)+,d0/a0
  234. return3
  235.     rts
  236.  
  237.  
  238.  
  239. hardAY_WrRegList:
  240. _hardAY_WrRegList:
  241.     ;write reglist to AY
  242.     ;a0   - ptr to reglist
  243.     ;d0.b - number of regs to out
  244.  
  245.     ;reglist: (regnumber).b,(regvalue).b, ...
  246.  
  247.     tst.w    Success
  248.     bne.s    return3
  249.  
  250.     movem.l    d0-d2/a0,-(sp)
  251.  
  252.     cmp.b    #16,d0
  253.     bls.s    .numok
  254.     moveq    #16,d0
  255. .numok
  256.  
  257. .loop
  258.     move.b    (a0)+,d1
  259.     move.b    (a0)+,d2
  260.  
  261.     cmp.b    #7,d1
  262.     bne.s    .no7
  263.  
  264.     move.b    d2,AYreg7
  265.     and.b    #$3F,d2
  266.     and.b    #$C0,AYreg7
  267.     or.b    #$40,d2
  268.     bra.s    .wrreg
  269. .no7
  270.     cmp.b    #14,d1
  271.     blo.s    .less14
  272.  
  273.     cmp.b    #15,d1
  274.     bhi.s    .endloop
  275.  
  276.     beq.s    .wr15
  277.     move.b    d2,AYreg14
  278.     bra.s    .endloop
  279. .wr15
  280.     move.b    d2,AYreg15
  281.     bra.s    .endloop
  282.  
  283. .less14
  284.  
  285. .wrreg
  286.     WR_REG    d1,d2
  287.  
  288. .endloop    
  289.     subq.b    #1,d0
  290.     bne.s    .loop
  291.  
  292.     movem.l    (sp)+,d0-d2/a0
  293. return2
  294.     rts
  295.  
  296.  
  297.  
  298.  
  299. hardAY_RdRegList:
  300. _hardAY_RdRegList:
  301.     ;will read reg content of AY
  302.     ;args same as in hardAY_WrRegList, but (regvalue).b will be filled with new data
  303.  
  304.     tst.w    Success
  305.     bne.s    return2
  306.  
  307.     movem.l    d0-d2/a0,-(sp)
  308.  
  309.     cmp.b    #16,d0
  310.     bls.s    .numok
  311.     moveq    #16,d0
  312. .numok
  313.  
  314. .loop
  315.     move.b    (a0)+,d1
  316.  
  317.     cmp.b    #14,d1
  318.     blo.s    .less14
  319.  
  320.     cmp.b    #15,d1
  321.     bhi.s    .endloop
  322.  
  323.     beq.s    .rd15
  324.     move.b    AYreg14(pc),d2
  325.     bra.s    .2mem
  326. .rd15
  327.     move.b    AYreg15(pc),d2
  328.     bra.s    .2mem
  329.  
  330. .less14
  331.     RD_REG    d1,d2
  332.  
  333.     cmp.b    #7,d1
  334.     bne.s    .no7
  335.     and.b    #$3F,d2
  336.     or.b    AYreg7(pc),d2
  337. .no7
  338.  
  339. .2mem
  340.     move.b    d2,(a0)
  341.  
  342. .endloop
  343.     addq.l    #1,a0
  344.  
  345.     subq.b    #1,d0
  346.     bne    .loop
  347.  
  348.  
  349.     movem.l    (sp)+,d0-d2/a0
  350. return1
  351.     rts
  352.  
  353.  
  354.  
  355.  
  356. hardAY_SetFreq:
  357. _hardAY_SetFreq:
  358.     ;sets frequency of AY
  359.     ;d0.l - freq (in Hz) - may be 1-2MHz, other will be truncated
  360.  
  361.     tst.w    Success
  362.     bne.s    return1
  363.  
  364.     movem.l    d0-d6/a0,-(sp)
  365.  
  366.     cmp.l    #1000000,d0
  367.     bhs.s    .moreeq1M
  368.     move.l    #1000000,d0
  369. .moreeq1M
  370.     cmp.l    #2000000,d0
  371.     bls.s    .lesseq2M
  372.     move.l    #2000000,d0
  373. .lesseq2M
  374.  
  375.     lea    FreqTable(pc),a0
  376.     moveq    #-1,d1
  377.  
  378. .selloop
  379.     move.l    (a0)+,d2
  380.     beq.s    .endloop
  381.     bpl.s    .checkfit
  382.     move.l    d2,d3
  383.     neg.l    d3
  384.     bra.s    .selloop
  385. .checkfit
  386.  
  387.     move.l    d2,d4
  388.     sub.l    d0,d4
  389.     bpl.s    .noneg
  390.     neg.l    d4
  391. .noneg
  392.  
  393.     cmp.l    d1,d4
  394.     bhs.s    .selloop
  395.  
  396.     move.l    d4,d1
  397.     move.l    d2,d5
  398.     move.l    d3,d6
  399.  
  400.     bra.s    .selloop
  401. .endloop
  402.  
  403.     move.l    d6,d4
  404.     moveq    #-3,d0
  405. .calcrem
  406.     addq.b    #1,d0
  407.     sub.l    d5,d4
  408.     bcc.s    .calcrem
  409.  
  410.     and.b    #$0F,d0
  411.     cmp.l    #14000000,d6
  412.     bne.s    .no14M
  413.     or.b    #$10,d0
  414. .no14M
  415.     WR_REG    #14,d0
  416.  
  417.     movem.l    (sp)+,d0-d6/a0
  418.  
  419.     rts
  420.  
  421.  
  422.  
  423.  
  424.  
  425.  
  426.  
  427.  
  428.  
  429.  
  430.     cnop    0,4
  431.  
  432. FreqTable    dc.l    -14000000,2000000        ;check freqs in descending order
  433.     dc.l    -8867238,1773447
  434.     dc.l    -14000000,1750000,1555555
  435.     dc.l    -8867238,1477873
  436.     dc.l    -14000000,1400000,1272727
  437.     dc.l    -8867238,1266748
  438.     dc.l    -14000000,1166666
  439.     dc.l    -8867238,1108404
  440.     dc.l    -14000000,1076923,1000000
  441.     dc.l    0
  442.  
  443. MiscBase    dc.l    0
  444.  
  445. Success    dc.w    0
  446.  
  447. ClearSeq    dc.w    $0000,$0100,$0200,$0300,$0400,$0500,$0600,$07FF
  448.     dc.w    $0800,$0900,$0A00,$0B00,$0C00,$0D00,$0E00,$0F00
  449.  
  450. AYreg7    dc.b    0
  451. AYreg14    dc.b    0
  452. AYreg15    dc.b    0
  453.  
  454. MiscResName    dc.b    'misc.resource',0
  455. OwnerString    dc.b    'hardAY interface of mAYhem package',0
  456.